import Vue from 'vue';
import Router from 'vue-router';
import systemRoutes from './system/systemRoutes';
import taskmanagerRoutes from './taskmanage/taskmanagerRoutes';
import tpproxyRoutes from './tpproxy/tpproxyRoutes';
import wechatmallRoutes from './wechatmall/wechatmallRoutes';

const _import = require('./_import_' + process.env.NODE_ENV);
// in development env not use Lazy Loading,because Lazy Loading large page will cause webpack hot update too slow
// 所以只在生产中使用延迟加载
/* login */
const Login = _import('login/index');
const sendPWD = _import('login/sendpwd');
const reset = _import('login/reset');
/* 权限 */
const Err404 = _import('error/404');
const Err401 = _import('error/401');
// const dashboard = _import('home/dashboard');
import Layout from '@/views/layout/Layout';

Vue.use(Router);
/** 路由对象额外属性注释
 * icon : 菜单图标
 * hidden : true不显示在菜单栏
 * redirect : noredirect 为不重定向
 * nodropdown : true 不显示子菜单
 * isadmin : 是否系统管理员only
 * isconstant:是否是固定路由
 * componentpath :组件路径
 **/
// 固定路由map,跟权限无关的固定页面
export const constantRouterMap = [
  // 登录
  {path: '/login', name: '登录', component: Login, hidden: true, isconstant: true},
  // 忘记密码发送到邮箱
  {path: '/sendpwd', name: '发送密码', component: sendPWD, hidden: true, isconstant: true},
  // 重置密码
  {path: '/reset', name: '重置密码', component: reset, hidden: true, isconstant: true},
  // 404
  {path: '/404', name: '404', component: Err404, hidden: true, isconstant: true},
  // 无权限时重定向
  {path: '/401', name: '401', component: Err401, hidden: true, isconstant: true},
  {path: '/', name: 'index', component: Layout, hidden: true, isconstant: true, redirect: '/home/dashboard'}
];
// 动态路由表
export const asyncRouterMap = [
  // 首页(固定的)
  {
    path: '/home',
    componentpath: 'layout/Layout',
    redirect: '/dashboard',
    nodropdown: true,
    isconstant: true,
    icon: 'home',
    children: [{
      path: 'dashboard',
      componentpath: 'home/dashboard',
      name: '首页',
      isconstant: true
    }]
  }, systemRoutes, tpproxyRoutes, wechatmallRoutes, taskmanagerRoutes

];
export default new Router({
  // mode: 'history', //后端支持可开
  scrollBehavior: () => ({y: 0}),
  routes: constantRouterMap
});
